package cn.sc.summer.adapter.controller;

import cn.sc.summer.constant.model.PageResult;
import cn.sc.summer.constant.model.Result;
import cn.sc.summer.domain.role.SysRoleService;
import cn.sc.summer.protocol.ValidatedGroup;
import cn.sc.summer.protocol.form.role.RoleBindForm;
import cn.sc.summer.protocol.form.role.RoleForm;
import cn.sc.summer.protocol.form.role.RoleGetForm;
import cn.sc.summer.protocol.vo.role.RoleInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 类名：角色管理控制层
 *
 * @author a-xin
 * @date 2023/11/27 08:17
 */
@Slf4j
@RestController
@RequestMapping("/role")
@Api(tags = "role-角色管理控制层")
public class SysRoleController {

    @Resource
    private SysRoleService sysRoleService;

    @PostMapping("/addRole")
    @ApiOperation(value = "新增角色信息")
    public Result<String> addRole(@Validated(ValidatedGroup.ADD_ROLE.class) @RequestBody RoleForm form) {
        return Result.success(sysRoleService.addRole(form));
    }

    @PostMapping("/updateRole")
    @ApiOperation(value = "更新角色信息")
    public Result<Boolean> updateRole(@Validated(ValidatedGroup.UPDATE_ROLE.class) @RequestBody RoleForm form) {
        return Result.success(sysRoleService.updateRole(form));
    }

    @GetMapping("/delRole")
    @ApiOperation(value = "删除角色信息")
    public Result<Boolean> delRole(@RequestParam(value = "roleId") String roleId) {
        return Result.success(sysRoleService.delRole(roleId));
    }

    @PostMapping("/getAllRole")
    @ApiOperation(value = "获取所有角色信息")
    public Result<PageResult<RoleInfoVO>> getAllRole(@RequestBody RoleGetForm form) {
        return Result.success(sysRoleService.getAllRole(form));
    }

    @PostMapping("/roleBindRoute")
    @ApiOperation(value = "角色绑定路由信息")
    public Result<Boolean> roleBindRoute(@Validated @RequestBody RoleBindForm form) {
        return Result.success(sysRoleService.roleBindRoute(form));
    }

}
